package logic

import (
	"context"
	"weixin/models/mysql"

	"weixin/weixinrpc/internal/svc"
	"weixin/weixinrpc/weixinrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserAddLogic) UserAdd(in *weixinrpc.UserAddRequest) (*weixinrpc.UserAddResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.User{
		Nickname:  in.Nickname,
		Name:      in.Name,
		HeadImage: in.HeadImage,
		Tel:       in.Tel,
		Uptime:    in.Uptime,
		Price:     float64(in.Price),
	}
	mysql.DB.Debug().Create(&user)
	return &weixinrpc.UserAddResponse{
		Id: int64(user.ID),
	}, nil
}
